<%@ page import="com.h.heal.entity.Admin" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>HEAL评论添加</title>
   <jsp:include page="../../common_css.jsp"/>

    <style>
        .form-control{
            width: 30%;
        }
    </style>
</head>
<body style="background: linear-gradient(to top right, #a1ffce 0%, #faffd1 100%);">
<div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <jsp:include page="../../top.jsp"/>

    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
        <!-- partial:partials/_sidebar.html -->
        <jsp:include page="../../left.jsp"/>
        <!-- partial -->
        <div class="main-panel">
                <div class="row">
                    <div class="col-md-12 stretch-card">
                        <div class="card"style="background: rgba(255,255,255,0);border: none;">
                            <div class="card-body">

                                <div class="table-responsive" align="center">


                                    <form id="frm" class="form-signin">
<%--                                        <img class="mb-4" src="${pageContext.request.contextPath}/style/images/Logo with Inverted Palette - No Background.png" alt="" width="50" height="50">--%>
                                        <h1 class="h3 mb-3 font-weight-normal">添加评论</h1>
<%--                                        <label for="input_product_id" class="sr-only">产品编号</label>--%>
<%--                                        <input type="text" id="input_product_id" name="product_id" class="form-control" placeholder="产品编号" required autofocus>--%>


                                        <label for="input_comment_uid" class="sr-only">作者UID</label>
                                        <input type="text" id="input_comment_uid"  name="comment_uid" class="form-control" placeholder="作者UID" >

                                        <label for="input_comment_vid" class="sr-only">视频VID</label>
                                        <input type="text" id="input_comment_vid" name="comment_vid" class="form-control" placeholder="视频VID" >

                                        <label for="input_comment_maintext" class="sr-only">评论内容</label>
                                        <textarea type="text" id="input_comment_maintext" name="comment_maintext" class="form-control"  style="height: 200px" placeholder="评论内容" ></textarea>

                                        <button class="btn btn-lg btn-primary btn-block" type="button" onclick="create()" style="width: 30%">添加</button>
                                    </form>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


           <jsp:include page="../../footer.jsp"/>
        </div>
        <!-- main-panel ends -->
    </div>
    <!-- page-body-wrapper ends -->
</div>
<!-- container-scroller -->
<jsp:include page="../../common_js.jsp"/>
</body>

</html>

<script>
    function create() {
        //推荐前端js验证字段

        var comment_uid=$("#input_comment_uid").val();
        var comment_vid=$("#input_comment_vid").val();
        var comment_maintext=$("#input_comment_maintext").val();
        if (comment_uid=='' || comment_uid== null || comment_vid=='' || comment_vid== null || comment_maintext=='' || comment_maintext== null){
            alert("以上内容不能为空");
       }else{
            var reg_uid = /^[0-9]*$/
            var reg_vid = /^[0-9]*$/
            if (!reg_uid.test(comment_uid)){
                alert("请输入纯数字用户uid")
            }else if (!reg_vid.test(comment_vid)){
                alert("请输入纯数字视频vid")
            }else {
            $.ajax(
                {
                    type:"post",
                    url:"/comment/create",
                    data:$("#frm").serialize(),
                    async:false,  //使用ajax同步提交数据
                    success:function (response) {
                        if (response=="exist"){
                            alert("添加失败，文章已经存在");
                        }else  if (response=="ok"){
                            // alert("添加成功,1秒后跳转到产品列表");
                            setTimeout(window.location.href="/comment/main",500);
                        }else{
                            alert("添加失败，请联系管理员....");
                        }
                    }
                }
            );
       }}
    }
</script>

